﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using Jungle.Code.Utils;
using Jungle.Code.Core;

using Jungle.Code.CategoryManager;
using Jungle.Code.ProductManager;

namespace Jungle.Code.ProductManager.WebControls
{
    public class ProductsListUserPart: WebControl
    {
        //--------------------------------------------------------------------
        protected override void RenderContents(HtmlTextWriter writer)
        {
            int catId = -1;
            string cmd = "";
            int pId = -1;
            string catName = "";
            
            string linkStr = Context.Request.RawUrl;
            linkStr = linkStr.Substring(0, linkStr.IndexOf("main.aspx") + 9);


            if (Context.Request["catId"] != null)
            { 
                catId = Convert.ToInt32(Context.Request["catId"]);                 
                JungleTreeMenu jM = new JungleTreeMenu();
                jM.ID = catId;
                jM.GetById();
                catName = jM.MenuText.Trim();
            }
            if (Context.Request["cmd"] != null)
            { cmd = Context.Request["cmd"]; }
            if (Context.Request["pId"] != null)
            { pId = Convert.ToInt32(Context.Request["pId"]); }

            Product p = new Product();

            #region ProductsListTable

            if (cmd != "" && catId != -1)
             {
                

                JungleTreeMenu jMenuItem = new JungleTreeMenu();
                jMenuItem.ID = catId;
                jMenuItem.GetById();

            if (jMenuItem.GetChildItems() > 1)
            {
                #region показать в выбранном каталоге с подкаталогами
                                
                    foreach (JungleTreeMenu jSubCat in jMenuItem.MenuItemsList)
                    {
                        p.GetByCategoryId(jSubCat.ID);
                        foreach (Product pr in p.ProductsList)
                        {
                            if (pr.Visible)
                            {

                                #region DIV

                                writer.AddAttribute("class", "catalog_item");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog item start


                                writer.AddAttribute("style", "cellpadding:0px; cellspacing:0px;");
                                writer.RenderBeginTag(HtmlTextWriterTag.Table);

                                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                                writer.RenderBeginTag(HtmlTextWriterTag.Td);

                                //TABLE


                                writer.AddAttribute("class", "catalog_item_photo");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//img start

                                //image
                                try
                                {
                                    string[] ImagesUrls = pr.ImagePath.ToString().Split(',');
                                    if (ImagesUrls[0] == "no_photo")
                                        writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                                    else
                                        writer.AddAttribute(HtmlTextWriterAttribute.Src, ImagesUrls[0].Trim());                                        
                                }
                                catch (Exception ee)
                                {
                                    writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                                }  
                                writer.RenderBeginTag(HtmlTextWriterTag.Img);
                                writer.RenderEndTag();

                                writer.Write("<br>");

                                writer.AddAttribute("class", "catalog_viev_addition_link");
                                writer.AddAttribute(HtmlTextWriterAttribute.Href, "?cmd=viewProduct&pId=" + pr.ProductId.ToString() + "&large=1");
                                writer.RenderBeginTag(HtmlTextWriterTag.A);
                                writer.Write("Посмотреть увеличенное");
                                writer.RenderEndTag();

                                writer.RenderEndTag();//img end


                                writer.AddAttribute("class", "catalog_item_information_container");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog_item_information_container start

                                writer.AddAttribute("class", "catalog_info_title");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                                writer.Write(pr.Title);
                                writer.RenderEndTag();//title end
                                writer.Write("<br>");


                                writer.AddAttribute("class", "catalog_item_number");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//cat num start
                                writer.Write("Каталожный номер: " + pr.CatalogNumber);
                                writer.RenderEndTag();//cat num end
                                writer.Write("<br>");

                                writer.AddAttribute("class", "catalog_item_description");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                                writer.Write(pr.Description);
                                writer.RenderEndTag();//title end                        

                                writer.AddAttribute("class", "catalog_item_old_price");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                                writer.Write("Рыночная цена: " + pr.MarketPrice.ToString());
                                writer.RenderEndTag();//title end


                                writer.AddAttribute("class", "catalog_item_our_price");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                                writer.Write("Цена сайта: " + pr.Price.ToString());
                                writer.RenderEndTag();//title end

                                writer.Write("<br />");
                                writer.AddAttribute("class", "catalog_item_old_price");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                                writer.AddAttribute("class", "catalog_item_view_additions");
                                writer.AddAttribute(HtmlTextWriterAttribute.Href, linkStr + "?cmd=viewProduct&pId=" + pr.ProductId.ToString());
                                writer.RenderBeginTag(HtmlTextWriterTag.A);
                                writer.Write("Подробнее...");
                                writer.RenderEndTag();
                                writer.RenderEndTag();//title end

                                writer.RenderEndTag(); //catalog_item_information_container start                    

                                writer.RenderEndTag();
                                writer.RenderEndTag();
                                //TABLE
                                writer.RenderEndTag();

                                writer.RenderEndTag(); //catalog item end 


                                writer.AddAttribute("class", "clear2");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                                writer.RenderEndTag();

                                //separator
                                writer.AddAttribute(HtmlTextWriterAttribute.Style, "height:10px; margin-top:0px;");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                                writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;");
                                writer.RenderBeginTag(HtmlTextWriterTag.Table);
                                writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                                writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                                writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_left.gif");
                                writer.RenderBeginTag(HtmlTextWriterTag.Img);
                                writer.RenderEndTag();
                                writer.RenderEndTag();

                                writer.AddAttribute("class", "separator_middle");
                                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                                writer.Write("&nbsp;");
                                writer.RenderEndTag();


                                writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                                writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_right.gif");
                                writer.RenderBeginTag(HtmlTextWriterTag.Img);
                                writer.RenderEndTag();
                                writer.RenderEndTag();

                                writer.RenderEndTag();
                                writer.RenderEndTag();
                                writer.RenderEndTag();
                                //separator end
                                

                                //separator end
                                



                                #endregion

                            }
                        }  
                    }

                #endregion
             }
            else
             {              
                #region Показать все товары в выбранном каталоге

                    p.GetByCategoryId(catId);

                    //writer.AddAttribute("style", "height:22px; background-color:#2a8c0f; margin-top:0px;");
                    //writer.RenderBeginTag(HtmlTextWriterTag.Div);

                    //writer.AddAttribute("class", "rss_table");
                    //writer.RenderBeginTag(HtmlTextWriterTag.Table);
                    //writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    //writer.AddAttribute("class", "rss_table_td");
                    //writer.RenderBeginTag(HtmlTextWriterTag.Td);                    
                    //writer.Write(catName);
                    ////writer.AddAttribute("class", "rss_link");
                    ////writer.AddAttribute(HtmlTextWriterAttribute.Href, "/rss.aspx?catId=" + catId.ToString());
                    ////writer.Write("&nbsp;");
                    ////writer.RenderBeginTag(HtmlTextWriterTag.A);
                    ////writer.AddAttribute("class", "rss_img");
                    ////writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/rss.jpg");
                    ////writer.RenderBeginTag(HtmlTextWriterTag.Img);                 
                    ////writer.RenderEndTag();
                    ////writer.RenderEndTag();
                    //writer.RenderEndTag();
                    //writer.RenderEndTag();
                    //writer.RenderEndTag();

                    //writer.RenderEndTag();

                    foreach (Product pr in p.ProductsList)
                    {
                        if (pr.Visible)
                        {

                            #region DIV

                            writer.AddAttribute("class", "catalog_item");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog item start

                            //TABLE
                            writer.AddAttribute("style", "cellpadding:0px; cellspacing:0px;");
                            writer.RenderBeginTag(HtmlTextWriterTag.Table);

                            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                            writer.RenderBeginTag(HtmlTextWriterTag.Td);

                            //TABLE

                            writer.AddAttribute("class", "catalog_item_photo");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//img start

                            //image
                            try
                            {
                                string[] ImagesUrls = pr.ImagePath.ToString().Split(',');
                                if (ImagesUrls[0] == "no_photo")
                                    writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                                else
                                    writer.AddAttribute(HtmlTextWriterAttribute.Src, ImagesUrls[0].Trim()); 
                            }
                            catch (Exception ee)
                            {
                                writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                            }  

                            writer.RenderBeginTag(HtmlTextWriterTag.Img);
                            writer.RenderEndTag();

                            writer.Write("<br>");

                            writer.AddAttribute("class", "catalog_viev_addition_link");
                            writer.AddAttribute(HtmlTextWriterAttribute.Href, "?cmd=viewProduct&pId=" + pr.ProductId.ToString() + "&large=1");
                            writer.RenderBeginTag(HtmlTextWriterTag.A);
                            writer.Write("Посмотреть увеличенное");
                            writer.RenderEndTag();

                            writer.RenderEndTag();//img end


                            writer.AddAttribute("class", "catalog_item_information_container");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog_item_information_container start

                            writer.AddAttribute("class", "catalog_info_title");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                            writer.Write(pr.Title);
                            writer.RenderEndTag();//title end
                            writer.Write("<br>");


                            writer.AddAttribute("class", "catalog_item_number");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//cat num start
                            writer.Write("Каталожный номер: " + pr.CatalogNumber);
                            writer.RenderEndTag();//cat num end
                            writer.Write("<br>");

                            writer.AddAttribute("class", "catalog_item_description");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                            writer.Write(pr.Description);
                            writer.RenderEndTag();//title end                        

                            writer.AddAttribute("class", "catalog_item_old_price");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                            writer.Write("Рыночная цена: " + pr.MarketPrice.ToString());
                            writer.RenderEndTag();//title end


                            writer.AddAttribute("class", "catalog_item_our_price");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                            writer.Write("Цена сайта: " + pr.Price.ToString());
                            writer.RenderEndTag();//title end

                            writer.Write("<br />");
                            writer.AddAttribute("class", "catalog_item_old_price");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                            writer.AddAttribute("class", "catalog_item_view_additions");
                            writer.AddAttribute(HtmlTextWriterAttribute.Href, linkStr + "?cmd=viewProduct&pId=" + pr.ProductId.ToString());
                            writer.RenderBeginTag(HtmlTextWriterTag.A);
                            writer.Write("Подробнее...");
                            writer.RenderEndTag();
                            writer.RenderEndTag();//title end

                            writer.RenderEndTag(); //catalog_item_information_container start

                            writer.RenderEndTag();
                            writer.RenderEndTag();
                            //TABLE
                            writer.RenderEndTag();


                            writer.RenderEndTag(); //catalog item end 
                            
                            writer.AddAttribute("class", "clear2");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);
                            writer.RenderEndTag();

                            //separator
                            writer.AddAttribute(HtmlTextWriterAttribute.Style, "height:10px; margin-top:0px;");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);

                            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                            writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;");
                            writer.RenderBeginTag(HtmlTextWriterTag.Table);
                            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                            writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                            writer.RenderBeginTag(HtmlTextWriterTag.Td);
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_left.gif");
                            writer.RenderBeginTag(HtmlTextWriterTag.Img);
                            writer.RenderEndTag();
                            writer.RenderEndTag();

                            writer.AddAttribute("class", "separator_middle");
                            writer.RenderBeginTag(HtmlTextWriterTag.Td);
                            writer.Write("&nbsp;");
                            writer.RenderEndTag();


                            writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                            writer.RenderBeginTag(HtmlTextWriterTag.Td);
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_right.gif");
                            writer.RenderBeginTag(HtmlTextWriterTag.Img);
                            writer.RenderEndTag();
                            writer.RenderEndTag();

                            writer.RenderEndTag();
                            writer.RenderEndTag();
                            writer.RenderEndTag();
                            //separator end

                           



                            #endregion

                        }
                    }
                    #endregion
             }
            }
            else if (pId != -1)
            {
                #region Показать детальную инфу по товару

                p.ProductId = pId;
                p.GetByProductId();

                if (p.Visible)
                {

                    

                    writer.AddAttribute("class", "catalog_item");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog item start

                    writer.AddAttribute("style", "cellpadding:0px; cellspacing:0px;");
                    writer.RenderBeginTag(HtmlTextWriterTag.Table);

                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);

                    //TABLE

                    writer.AddAttribute("class", "catalog_item_photo");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//img start

                    //image
                    try
                    {
                        string[] ImagesUrls = p.ImagePath.ToString().Split(',');
                        if (ImagesUrls[0] == "no_photo")
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                        else
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, ImagesUrls[0].Trim()); 
                    }
                    catch (Exception ee)
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                    }  

                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();

                    writer.Write("<br>");

                    writer.AddAttribute("class", "catalog_viev_addition_link");
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "?cmd=viewProduct&pId=" + p.ProductId.ToString() + "&large=1");
                    writer.RenderBeginTag(HtmlTextWriterTag.A);                    
                    writer.Write("Посмотреть увеличенное");                    
                    writer.RenderEndTag();

                    writer.RenderEndTag();//img end


                    writer.AddAttribute("class", "catalog_item_information_container");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog_item_information_container start

                    writer.AddAttribute("class", "catalog_info_title");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write(p.Title);
                    writer.RenderEndTag();//title end
                    writer.Write("<br>");


                    writer.AddAttribute("class", "catalog_item_number");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//cat num start
                    writer.Write("Каталожный номер: " + p.CatalogNumber);
                    writer.RenderEndTag();//cat num end
                    writer.Write("<br>");

                    writer.AddAttribute("class", "catalog_item_description");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write(p.Description);
                    writer.RenderEndTag();//title end                        

                    writer.AddAttribute("class", "catalog_item_old_price");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write("Рыночная цена: " + p.MarketPrice.ToString());
                    writer.RenderEndTag();//title end


                    writer.AddAttribute("class", "catalog_item_our_price");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write("Цена сайта: " + p.Price.ToString());
                    writer.RenderEndTag();//title end

                    writer.Write("<br />");

                    writer.AddAttribute("class", "catalog_item_old_price");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    ProductType pt = new ProductType();
                    pt.TypeId = p.TypeId;
                    pt.GetById();                    
                    writer.Write("Тип товара: " + pt.TypeDescription);
                    writer.RenderEndTag();//title end
                    
                    writer.AddAttribute("class", "catalog_item_old_price");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write("Минимальный заказ: " + p.MinimalOrder.ToString() + " шт.");
                    writer.RenderEndTag();//title end

                    writer.AddAttribute("class", "catalog_item_old_price");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write("Вес: " + p.Weight.ToString() + " кг.");
                    writer.RenderEndTag();//title end

                    writer.AddAttribute("class", "catalog_item_our_price");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                    writer.Write("<strong><a href=\"javascript:history.go(-1)\" style=\"text-decoration:none; color:#d0333a;\">Назад</a></strong>");
                    writer.RenderEndTag();//title end

                    

                    writer.RenderEndTag(); //catalog_item_information_container start  

                    writer.RenderEndTag();
                    writer.RenderEndTag();
                    //TABLE
                    writer.RenderEndTag();

                    writer.RenderEndTag(); //catalog item end


                    

                    writer.AddAttribute("class", "clear2");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);
                    writer.RenderEndTag();
                    

                    //separator
                    writer.AddAttribute(HtmlTextWriterAttribute.Style, "height:10px; margin-top:0px; width:100%;");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);

                    writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                    writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                    writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;");
                    writer.RenderBeginTag(HtmlTextWriterTag.Table);
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                    writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_left.gif");
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();
                    writer.RenderEndTag();

                    writer.AddAttribute("class", "separator_middle");
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write("&nbsp;");
                    writer.RenderEndTag();


                    writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_right.gif");
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();
                    writer.RenderEndTag();

                    writer.RenderEndTag();
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                    //separator end                    
                    

                
                }
                #endregion
            }
            else if (cmd == "" && Context.Request.RawUrl.IndexOf("main.aspx") != -1)
            {
                #region Показать все товары в выбранном каталоге

                p.GetByCategoryId(2);

                foreach (Product pr in p.ProductsList)
                {
                    if (pr.Visible)
                    {

                        #region DIV

                        writer.AddAttribute("class", "catalog_item");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog item start

                        //TABLE
                        writer.AddAttribute("style", "cellpadding:0px; cellspacing:0px;");
                        writer.RenderBeginTag(HtmlTextWriterTag.Table);

                        writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);

                        //TABLE

                        writer.AddAttribute("class", "catalog_item_photo");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//img start                        

                        //image
                        try
                        {
                            string[] ImagesUrls = pr.ImagePath.ToString().Split(',');
                            if (ImagesUrls[0] == "no_photo")
                                writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                            else
                                writer.AddAttribute(HtmlTextWriterAttribute.Src, ImagesUrls[0].Trim()); 
                        }
                        catch (Exception ee)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.Src, "/UserFiles/Images/Content/no_photo.jpg");
                        }  

                        writer.RenderBeginTag(HtmlTextWriterTag.Img);
                        writer.RenderEndTag();

                        //image


                        writer.Write("<br>");

                        writer.AddAttribute("class", "catalog_viev_addition_link");
                        writer.AddAttribute(HtmlTextWriterAttribute.Href, "?cmd=viewProduct&pId=" + pr.ProductId.ToString() + "&large=1");
                        writer.RenderBeginTag(HtmlTextWriterTag.A);
                        writer.Write("Посмотреть увеличенное");
                        writer.RenderEndTag();

                        writer.RenderEndTag();//img end


                        writer.AddAttribute("class", "catalog_item_information_container");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div); //catalog_item_information_container start

                        writer.AddAttribute("class", "catalog_info_title");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                        writer.Write(pr.Title);
                        writer.RenderEndTag();//title end
                        writer.Write("<br>");


                        writer.AddAttribute("class", "catalog_item_number");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//cat num start
                        writer.Write("Каталожный номер: " + pr.CatalogNumber);
                        writer.RenderEndTag();//cat num end
                        writer.Write("<br>");

                        writer.AddAttribute("class", "catalog_item_description");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                        writer.Write(pr.Description);
                        writer.RenderEndTag();//title end                        

                        writer.AddAttribute("class", "catalog_item_old_price");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                        writer.Write("Рыночная цена: " + pr.MarketPrice.ToString());
                        writer.RenderEndTag();//title end


                        writer.AddAttribute("class", "catalog_item_our_price");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                        writer.Write("Цена сайта: " + pr.Price.ToString());
                        writer.RenderEndTag();//title end

                        writer.Write("<br />");
                        writer.AddAttribute("class", "catalog_item_old_price");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);//title start
                        writer.AddAttribute("class", "catalog_item_view_additions");
                        writer.AddAttribute(HtmlTextWriterAttribute.Href, linkStr + "?cmd=viewProduct&pId=" + pr.ProductId.ToString());
                        writer.RenderBeginTag(HtmlTextWriterTag.A);
                        writer.Write("Подробнее...");
                        writer.RenderEndTag();
                        writer.RenderEndTag();//title end

                        writer.RenderEndTag(); //catalog_item_information_container start                  


                        writer.RenderEndTag();
                        writer.RenderEndTag();
                        //TABLE
                        writer.RenderEndTag();

                        writer.RenderEndTag(); //catalog item end


                        writer.AddAttribute("class", "clear2");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);
                        writer.RenderEndTag();

                        //separator
                        writer.AddAttribute(HtmlTextWriterAttribute.Style, "height:10px; margin-top:0px;");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);

                        writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                        writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                        writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;");
                        writer.RenderBeginTag(HtmlTextWriterTag.Table);
                        writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                        writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);
                        writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_left.gif");
                        writer.RenderBeginTag(HtmlTextWriterTag.Img);
                        writer.RenderEndTag();
                        writer.RenderEndTag();

                        writer.AddAttribute("class", "separator_middle");
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);
                        writer.Write("&nbsp;");
                        writer.RenderEndTag();


                        writer.AddAttribute(HtmlTextWriterAttribute.Width, "8px");
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);
                        writer.AddAttribute(HtmlTextWriterAttribute.Src, "/App_Themes/img/separator_right.gif");
                        writer.RenderBeginTag(HtmlTextWriterTag.Img);
                        writer.RenderEndTag();
                        writer.RenderEndTag();

                        writer.RenderEndTag();
                        writer.RenderEndTag();
                        writer.RenderEndTag();
                        //separator end

                         

                        #endregion

                    }
                }
                #endregion
            }

            #endregion

                base.RenderContents(writer);
        }     
        //-----------------------------------------------------------------------------------------------
        public HtmlTextWriter PrintBtnDel(HtmlTextWriter writer, int catId)
        {
            ClientScriptManager cs = Page.ClientScript;
            PostBackOptions opt = new PostBackOptions(this);
            opt.ActionUrl = Context.Request.RawUrl;
            opt.Argument = "delCategory," + catId.ToString();

            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "if(confirm(\"Вы действительно хотите удалить данную категорию? Все дочерние категории будут не доступны для просмотра в меню. \"))" + cs.GetPostBackEventReference(opt));
            writer.AddAttribute("title", "Удалить");
            writer.AddAttribute("style", "cursor: pointer;");
            PrintImage(writer, "/Admin/img/btn_blue_delete.png");
            return writer;
        }
        //-----------------------------------------------------------------------------------------------
        public HtmlTextWriter PrintBtnEdit(HtmlTextWriter writer, int catId)
        {
            string linkStr = Context.Request.RawUrl;
            int t = linkStr.IndexOf("cmd");

            if (t != -1)
            {
                linkStr = linkStr.Substring(0, t + 4);
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Href, linkStr + "editCategory&id=" + catId.ToString());
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.AddAttribute("title", "Редактировать");
            writer.AddAttribute("style", "cursor: pointer;");
            PrintImage(writer, "/Admin/img/btn_blue_edit.png");
            writer.RenderEndTag();
            return writer;
        }
        //-----------------------------------------------------------------------------------------------
        public HtmlTextWriter PrintText(HtmlTextWriter writer, string Text, int cID)
        {
            string link = Context.Request.RawUrl;
            if (Context.Request.RawUrl.IndexOf("&catId=") != -1)
            {
                link = link.Substring(0, link.IndexOf("&catId="));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Href, link + "&catId=" + cID.ToString());
            writer.AddAttribute("style", "cursor: pointer;");
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.Write(Text + "!");
            writer.RenderEndTag();
            return writer;
        }
        //-----------------------------------------------------------------------------------------------
        public HtmlTextWriter PrintImage(HtmlTextWriter writer, string imgUrl)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Src, UrlHelper.GetSiteUrl() + imgUrl);
            writer.AddAttribute(HtmlTextWriterAttribute.Align, "absmiddle");
            writer.RenderBeginTag(HtmlTextWriterTag.Img);
            writer.RenderEndTag();
            return writer;
        }
        //-----------------------------
    }
}
